<template>
  <div class="common-header">
    <!-- 头部 -->
    <div class="header">
      百慕大影院后台管理系统
      <div class="userinfo" v-if="$store.state.userInfo">
        {{ $store.state.userInfo.nickname }}
        <span @click="logout()">[注销]</span>
      </div>
      <div class="userinfo" v-else>未登录</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CommonHeader",
  data() {
    return {};
  },
  methods: {
    logout() {
      //调用vuex的方法注销用户信息
      this.$store.commit("clearUserState");
      this.$router.push("/user/login");
    },
  },
};
</script>

<style lang="scss" scoped>
.common-header {
  background-color: #333;
  color: #fff;
  line-height: 60px;
  font-size: 1.3em;
  .header {
    margin-left: 20px;
    .userinfo {
      color: white;
      float: right;
      font-size: 18px;
      margin-right: 30px;
      span:hover {
        color: #999;
        cursor: pointer;
      }
    }
  }
}
</style>
